require('../../css/jeui/skin/jedate.css')
require('./index.less');
import $ from 'jquery';
$(function() {

    $(".serch-btn").click(function() {
        var order_data_json = { "id": "1", "jsonrpc": "2.0", "method": "getReserveOrderList", "params": { "partnerId": "", type: "1", "transactionTypeId": $('#transactionTypeId').val(), "saleTypeId": "", "orderType": "", "playStartrDate": $("#inpstart").val(), "playEndDate": $("#inpend").val() } };
        var grouporderdata = $.ajax({
            contentType: "application/json;charset=utf-8",
            url: "/api/baseInfoApi",
            data: JSON.stringify(order_data_json),
            type: "post",
            dataType: "json"
        });
        grouporderdata.then(function(data) {
            $(".serch_all").empty();
            if (data.result.body == "SUCCESS") {
                $(".je-table").hide();
                $(".success").show();
            } else {
                $(".je-table").show();
                $(".success").hide();
                for (var i = 0; i < data.result.body.length; i++) {
                    console.log(data.result.body.length)
                    var odata = data.result.body[i];
                    odata.transaction = gettransaction(data.result.body[i].transactionTypeId);
                    odata.playdate = formattime(data.result.body[i].playdate);
                    odata.price = getprice(data.result.body[i].amount, data.result.body[i].number)
                    var serchtable = $("#serch_all").html();
                    var conReg = /(?:\{)(\w*)(?:\})/g;
                    var olisthtml = serchtable.replace(conReg, function(node, key) {
                        return odata[key];
                    });
                    $(".serch_all").append(olisthtml);
                }

            }


        })
    })
});

function gettransaction(n) {
    switch (n) {
        case 1:
            return "售票";
            break;
        case 2:
            return "退票";
            break;
        case 3:
            return "退余额";
            break;
        case 4:
            return "充值";
            break;
        default:
            return "售票";
            break;
    }
};

function getprice(a, n) {
    return a * n;
}

function formattime(date) {
    return date.substr(0, 10);
}